@extends('layouts.tankuang')

@section('content')
        <form name="add_form" id="add_form" action="{{url('admin/jq/addjq')}}" method="post" enctype="multipart/form-data">
            <input type="hidden" name="_token" value="{{ csrf_token() }}">
            <div id="div_print">
                <h2 class="text-center mg_b36 mg_t25" style="font-weight:bold;">警情上报</h2>

                <table class="table-form table-border w mg-auto">
                    <tbody>
                    <tr>
                        <td class="font-bd" width="12%">上报标题</td>
                        <td colspan="5"><input type="text" class="form-input w easyui-validatebox" value="" name="jqbt" data-options="required:true,missingMessage:'上报标题不能为空',validateOnCreate:false,validateOnBlur:true"></td>
                    </tr>

                    <tr>
                        <td class="font-bd">上报时间</td>
                        <td>
                             <input type="text" name="sbsj"  class="easyui-datetimebox" disabled/>

                        </td>
                        <td class="font-bd">县市区、派出所</td>
                        <td colspan="3">
                            <input type="text" class="form-input w" value="{{getValue($units->city,'area','id','name')}}{{getValue($units->area,'area','id','name')}}{{getValue($units->org_id,'area','id','name')}}" disabled>
                        </td>
                    </tr>

                        <tr>
                        <td class="font-bd">上报单位</td>
                        <td colspan="5"><input type="text" class="form-input w" value="{{$units->name}}" disabled></td>
                    </tr>


                     <tr>
                        <td class="font-bd">上报人</td>
                        <td>
                             <input type="text" class="form-input w153 easyui-validatebox" value="" name="sbren" data-options="required:true,missingMessage:'上报人不能为空',validateOnCreate:false,validateOnBlur:true">
                        </td>
                        <td class="font-bd">联系电话</td>
                        <td colspan="3">
                            <input type="text" class="form-input w easyui-validatebox" value="" name="lxfs" data-options="required:true,validType:'phoneAndMobile',missingMessage:'联系电话不能为空',invalidMessage:'请输入正确的联系电话',validateOnCreate:false,validateOnBlur:true">
                        </td>
                    </tr>

                     <tr>
                        <td class="font-bd">警情类型</td>
                        <td colspan="5">

                        <input type="radio" name="jqlx" value="1"  checked />发生不安定事端 /
                        <input type="radio" name="jqlx" value="2"  />刑事案件 /
                        <input type="radio" name="jqlx" value="3"  />抓获违法犯罪嫌疑人 /
                        <input type="radio" name="jqlx" value="4"  />上报情报信息 /
                        <input type="radio" name="jqlx" value="5"  />火灾事故数 /
                        <input type="radio" name="jqlx" value="6"  />其它灾害事故数

                        </td>
                    </tr>



                     <tr>
                        <td class="font-bd">警情内容</td>
                        <td colspan="5"><textarea class="textarea form-input w easyui-validatebox" name="cont" data-options="required:true,missingMessage:'警情内容不能为空',validateOnCreate:false,validateOnBlur:true" ></textarea></td>
                    </tr>




             

                    </tbody>
                </table>

            
                <div class="w wbt mg_t25 pd_b20 text-center">
                    <button id="go" type="button" class="easyui-linkbutton dsp" data-options="iconCls:'icon-save'">确定</button>
                    <button type="button" class="easyui-linkbutton dsp" data-options="iconCls:'icon-no'" onclick="$('#adbg').window('close')">关闭</button>
                </div>
            </div>
        </form>

        <script type="text/javascript">
            $(document).on("change",'#city', function(){

                $('#area option:gt(0)').remove();
                $('#org_id option:gt(0)').remove();
                //alert(1);die;
                var cid = $("#city").val();
                var url = "{{url('admin/getArea')}}";
                $.getJSON(url,{cid:cid},function(json){
                    /*清空原有的选项*/
                    if(json != ''){
                        $.each(json,function(index,array){
                            var option = "<option value='"+array['id']+"'";
                            option += ">"+array['name']+"</option>";
                            $("#area").append(option);
                        });
                    }
                });
            });

            $(document).on("change",'#area', function(){
                $('#org_id option:gt(0)').remove();
                var cid = $("#area").val();
                var url = "{{url('admin/getArea')}}";
                $.getJSON(url,{cid:cid},function(json){
                    /*清空原有的选项*/
                    if(json != ''){
                        $.each(json,function(index,array){
                            var option = "<option value='"+array['id']+"'";
                            option += ">"+array['name']+"</option>";
                            $("#org_id").append(option);
                        });
                    }
                });
            });
        </script>

        <script>
            $('#go').click(function (){
            	if(!$("#add_form").form('validate')){
					return false;
					}
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: "{{url('admin/jq/addjq')}}",
                    data: $('#add_form').serialize(),
                    async: false,
                    success: function(data) {
                        if(data.status == 1){
                            $.messager.alert('信息提示',data.msg,'info');
                            $('#adbg').dialog('close');
                            $('.pagination-load').click();
                        }else {
                            $.messager.alert('信息提示',data.msg,'info');
                        }
                    },
                    error: function(msg) {
                        var json=JSON.parse(msg.responseText);
                        $.each(json, function(index, value) {
                            $.messager.alert('信息提示',value,'info');die;
                        });
                    },
                });
            });
        </script>

        <script type="text/javascript">
             $(document).on("change",'#company', function(){
                var url = "{{url('admin/xz/findcompany')}}"
                var id = $("#company").val();
                
                if (id == '') {
                     $('#city option').remove();
                     $('#area option').remove();
                     $('#org_id option').remove();
                     document.getElementById("address").value = '';
                     document.getElementById('fzr').value = '';
                     document.getElementById('lxdh').value = '';

                }



                $.getJSON(url,{id:id},function(json){
                     console.log(json);
                    if (json != '') {
                        //获取详细地址
                        console.log(json['company']['address']);
                        var address = json['company']['address'];
                        document.getElementById("address").value = address;

                        //获取法人
                        var fzr = json['company']['frdb_name'];
                        document.getElementById("fzr").value = fzr;

                        //获取联系方式
                        var lxdh = json['company']['frdb_phone'];
                        document.getElementById('lxdh').value = lxdh;

                        //获取城市
                         $('#city option').remove();
                         $('#area option').remove();
                         $('#org_id option').remove();
                         
                        var option = "<option>"+json['city']['name']+"</option>";
                        $("#city").append(option);

                         var option = "<option>"+json['area']['name']+"</option>";
                        $("#area").append(option);


                         var option = "<option>"+json['org']['name']+"</option>";
                        $("#org_id").append(option);
                       
                    }
                });

            });


        </script>



@stop